[v2] Fix registerToolTask's getTask and getTaskResult handlers not being invoked#1332
Open
LucaButBoring wants to merge 11 commits intomodelcontextprotocol:mainfrom
Open
[v2] Fix registerToolTask's getTask and getTaskResult handlers not being invoked#1332LucaButBoring wants to merge 11 commits intomodelcontextprotocol:mainfrom
LucaButBoring wants to merge 11 commits intomodelcontextprotocol:mainfrom
Conversation
Previously, the code only called the underlying task store, and the tests were not complex enough to validate that the handlers were being called, so they missed this.
They weren't being populated correctly, and can't be without changing the TaskStore interface to require restoring the original request when retrieving a Task.
This removes the setTimeout logic we had in tests, which was masking an issue where the getTask handlers weren't being called. The appropriate logic has been moved into the getTask handlers themselves.
…ript-sdk into fix/registerToolTask
…ript-sdk into fix/registerToolTask
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
Contributor
Author
|
Either this or #1315 will need to be rebased after the other is merged. |
Contributor
|
hi, is this something to be backported to |
Contributor
Author
|
@KKonstantinov Yes, I'll open a separate PR for that shortly. |
9 tasks
Contributor
Author
|
Created #1335 against the |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug where custom
getTaskandgetTaskResulthandlers registered viaregisterToolTaskwere never invoked. TheProtocolclass's task handlers bypassed them entirely and usedTaskStoredirectly. This was a refactoring oversight that was missed due to (1) the existing tests not explicitly checking if those handlers were called, and (2)setTimeoutbeing used increateTaskin many tests inadvertently masking the issue.This also removes the argument-forwarding to
getTaskandgetTaskResult, as that was originally built before the currentTaskStoredesign was finalized, which broke the assumption that the original request would reliably be stored by the implementor. The currentTaskStoredesign allows theRequestto be saved, but does notrequirethat, and also exposes no way to directly retrieve it ingetTaskorgetTaskResult(it was possible but no longer intended at the time of the rewrite).getTaskandgetTaskResultnow only have theextraargument.Motivation and Context
When using
registerToolTask, developers could provide customgetTaskandgetTaskResulthandlers:These handlers were never invoked because:
Protocolclass'stasks/getandtasks/resulthandlers directly calledTaskStoreinstead of forwarding to the custom handlers.McpServer's backwards-compat polling wrapper also bypassed the custom handlerssetTimeoutto complete tasks and did not explicitly assert on the handlers being called, inadvertently masking the issue since tasks completed regardless of whether handlers were invokedHow Has This Been Tested?
Updated unit tests with stricter/more robust assertions.
Breaking Changes
Yes, due to
argsno longer being passed togetTaskorgetTaskResult.Types of changes
Checklist
Additional context